/**
 * @Author: wilmerxu
 * @Description: storage存储管理
 * @Date: 2020/6/27 14:48
 */
class Storage {
  /**
   * @Description 获取缓存
   * @Param String key
   * @return Object value
   **/
  get(key) {
    return new Promise((resolve => {
      chrome.storage.local.get([key], (result) => {
        console.log('Storage getValue:', result);
        resolve(result && result[key]);
      });
    }));
  }

  /**
   * @Description 设置缓存
   * @Param String key
   * @Param Object value
   * @return void
   **/
  set(key, value) {
    return new Promise(resolve => {
      // 保存到chrome缓存
      const data = {};
      data[key] = value;
      chrome.storage.local.set(data, () => {
        console.log('Storage setValue:', data);
        resolve(true);
      });
    });
  }
}

export default new Storage();
